#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long a, ans = 1;
    int b, p;
    cin >> a >> b >> p;
    long long cura = a;
    int curb = b;
    while (b > 0)
    {
        if ((b & 1) == 1)
        {
            ans = (ans * a) % p;
        }
        a = (a * a) % p;
        b >>= 1;
    }

    cout << cura << '^' << curb << " mod " << p << "=" << ans;
    return 0;
}
